package com.example.lt.authority;

import com.example.lt.util.JwtUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author 小涛Tao
 * @Date: 2024/08/17/18:28
 * version 1.0 注释：全局权限校验类
 **/
public class BaseAuthority implements AuthorityVerify{

    /**
     * 校验权限方法
     * @param request 请求信息
     * @param permissions 权限
     * @return
     */
    @Override
    public Boolean authorityVerify(HttpServletRequest request, String[] permissions) {
        if (!JwtUtil.checkToken(request)) {
            return false;
        }
        final Long userId = JwtUtil.getUserId(request);
        for (String permission : permissions) {
            if (!AuthorityUtils.verify(userId, permission)) {
                return false;
            }
        }
        return true;
    }

}
